import {
  getRegularList
} from '@/api/process/mesProcessMaterial'

export const regularDialog = {
  data() {
    return {
      regularDialogVisible: false,  // 正则表达式弹框隐藏显示
      getRegularList,  // 获取弹框数据接口
      regularSearchConfig: {
        inline: true,
        formDesc: {
          regularCode: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesProcess.regularCode')
          },
          regularName: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesProcess.regularName1')
          },
          regularContent: {
            type: 'input',
            layout: 8,
            label: $i18n.t('mesProcess.regularContent')
          }
        },
      },
      regularColumn: [
        {
          type: 'selection'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60
        },
        {
          prop: 'regularCode',
          label: $i18n.t('mesProcess.regularCode'),
          width: 120,
          showOverflowTooltip: true
        },
        {
          prop: 'regularName',
          label: $i18n.t('mesProcess.regularName1'),
          width: 150,
          showOverflowTooltip: true
        },
        {
          prop: 'regularContent',
          label: $i18n.t('mesProcess.regularContent'),
          width: 180,
          showOverflowTooltip: true
        },
        {
          prop: 'factoryCode',
          label: $i18n.t('common.factoryCode'),
          width: 120,
          showOverflowTooltip: true
        },
        {
          prop: 'remark',
          label: $i18n.t('common.remark'),
          showOverflowTooltip: true
        }
      ],
      regularDialogFooter: [  // 正则表达式查询dialog底部按钮
        {
          name: $i18n.t("common.cancel"),
        },
        {
          name: $i18n.t("common.ok"),
          type: 'primary',
          disabled: (data) => {
            return data.length !== 1;
          }
        },
      ],
    }
  },
  methods: {
    // 弹框表格，双击表格，或者点击确定 返回选中数据
    getSelectedRegular(data) {
      // 编辑时，正则表达式对应的是regularContent字段
      // 新增时，正则表达式对应的是materialList数组下regularContent字段
      if (this.dialogStatus === 'edit') {
        this.$set(this.formDataDialog, 'regularContent', data[0]['regularContent']);
        this.$set(this.formDataDialog, 'regularName', data[0]['regularName']);
        this.$set(this.formDataDialog, 'regularCode', data[0]['regularCode']);
      } else {
        this.$set(this.formDataDialog.materialList[this.selectedRowIndex], 'regularContent', data[0]['regularContent']);
        this.$set(this.formDataDialog.materialList[this.selectedRowIndex], 'regularName', data[0]['regularName']);
        this.$set(this.formDataDialog.materialList[this.selectedRowIndex], 'regularCode', data[0]['regularCode']);
      }
    },
    // 正则表达式查询dialog底部取消和确定按钮事件
    changeRegularDialog(data) {
      data.name === $i18n.t('common.ok') && this.getSelectedRegular(data.rows);
      this.regularDialogVisible = false;
    },
  }
}
